package com.wnhz.work.yz.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.wnhz.work.yz.BaseActivity;
import com.wnhz.work.yz.MyApplication;
import com.wnhz.work.yz.R;
import com.wnhz.work.yz.base.BaseLGAdapter;
import com.wnhz.work.yz.bean.LogisticsBean;
import com.wnhz.work.yz.bean.ShopProgressBean;
import com.wnhz.work.yz.utils.Url;
import com.wnhz.work.yz.utils.xutils3.MyCallBack;
import com.wnhz.work.yz.utils.xutils3.XUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 物流
 */
public class LogisticsActivity extends BaseActivity implements View.OnClickListener {

    private TextView title;
    private TextView ordrt_start;//订单状态
    private TextView source;//配送方式
    private TextView waybill_number;//运单编号
    private TextView phone_official;//官方电话
    private TextView good_num;//商品数量
    private ImageView good_img;//商品图片

    private ListView listView;
    private BaseLGAdapter<LogisticsBean> adapter;
    private List<LogisticsBean> list = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_logistics);
        String orderId = getIntent().getStringExtra("orderId");

        title = (TextView) findViewById(R.id.view_main_middle_title);
        title.setText("物流信息");
        findViewById(R.id.btn_main_left).setOnClickListener(this);

        ordrt_start = (TextView) findViewById(R.id.ordrt_start);
        source = (TextView) findViewById(R.id.source);
        waybill_number = (TextView) findViewById(R.id.waybill_number);
        phone_official = (TextView) findViewById(R.id.phone_official);
        good_num = (TextView) findViewById(R.id.good_num);
        good_img = (ImageView) findViewById(R.id.good_img);
        shopProgress(orderId);
    }

    private void setData() {

    }

    private ShopProgressBean.InfoEntity info1;

    private void shopProgress(String orderId) {
        Map<String, Object> map = new HashMap<>();
        map.put("token", MyApplication.getInstance().getUserBean().getToken());
        map.put("orderId", orderId);
        XUtil.Post(Url.ORDER_EXPRESSINFO, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    String res = jsonObject.optString("result");
                    String info = jsonObject.optString("info");
                    if ("1".equals(res)) {
                        //  MyToast(info);
                        //   upload(type);
                        Gson gson = new Gson();
                        ShopProgressBean bean = gson.fromJson(result, ShopProgressBean.class);
                        info1 = bean.getInfo();
                    } else {
                        MyToast(info);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }

            @Override
            public void onFinished() {
                setData();
                super.onFinished();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                super.onError(ex, isOnCallback);
            }
        });
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_main_left:
                finish();
                break;
        }
    }
}
